﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Controller;

public partial class Advogado: System.Web.UI.Page
{
    private DS_Lawyer.AdvogadoPrestadorDataTable dtAdvogadoPrestador
    {
        set { ViewState["dtAdvogadoPrestador"] = value; }
        get
        {
            object o = ViewState["dtAdvogadoPrestador"];
            if (o == null)
                return null;
            else
                return (DS_Lawyer.AdvogadoPrestadorDataTable)o;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            try
            {
                this.dtAdvogadoPrestador = cntrAdvogadoPrestador.Select();
                grdAdvogado.DataSource = this.dtAdvogadoPrestador;
                grdAdvogado.DataBind();
            }
            catch (Exception ex)
            {

                throw (new Exception(ex.Message));
            }
        }
    }
 
    protected void grdAdvogado_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            
            cntrAdvogadoPrestador.Delete(this.dtAdvogadoPrestador[e.RowIndex].idPrestador);

            this.dtAdvogadoPrestador = cntrAdvogadoPrestador.Select();
            grdAdvogado.DataSource = this.dtAdvogadoPrestador;
            grdAdvogado.DataBind();
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));

        }
       
    }

    protected void grdAdvogado_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            string idPrestador = this.dtAdvogadoPrestador[index].idPrestador;
            Response.Redirect("");

        }
    }

    protected void btnPesquisar_Click(object sender, ImageClickEventArgs e)
    {
        string criterio = txtBuscaNome.Text.Trim() + "%";

        this.dtAdvogadoPrestador = cntrAdvogadoPrestador.SelectByName(criterio);
        grdAdvogado.DataSource = this.dtAdvogadoPrestador;
        grdAdvogado.DataBind();
       
    }
   
}
